package com.geen.tuoke.ui.dialog

import android.content.Context
import androidx.databinding.DataBindingUtil
import com.blankj.utilcode.util.RegexUtils
import com.blankj.utilcode.util.ToastUtils
import com.geen.tuoke.R
import com.geen.tuoke.bean.request.AddTaskRequest
import com.geen.tuoke.databinding.DialogAddTaskPhoneBinding
import com.geen.tuoke.utils.ext.dp2px
import com.geen.tuoke.widget.dialog.DialogViewHolder
import com.geen.tuoke.widget.dialog.XXDialog
import com.qmuiteam.qmui.kotlin.onClick

/**
 * @Desc 添加号码弹窗
 */
class DialogAddTaskPhone(
    context: Context,
    var taskId: Int,
    private var onConfirm: (addTaskBean: AddTaskRequest) -> Unit
) : XXDialog(context, R.layout.dialog_add_task_phone) {

    private var addTaskBean = AddTaskRequest(taskId)
    private var mBinding: DialogAddTaskPhoneBinding? = null

    init {
        setWidthAndHeight(dp2px(288f), 0)
        setCanceledOnTouchOutside(false)

        mBinding?.run {
            data = addTaskBean
            ivClose.onClick {
                dismiss()
            }

            tvConfirm.onClick {

                if (!RegexUtils.isMobileExact(etPhone.text)) {
                    ToastUtils.showShort("手机号输入有误")
                    return@onClick
                }

                onConfirm(addTaskBean)
                dismiss()
            }

        }

    }


    override fun convert(holder: DialogViewHolder) {
        mBinding = DataBindingUtil.bind(holder.convertView)

    }

    fun reset() {
        addTaskBean.company = ""
        addTaskBean.name = ""
        addTaskBean.mobile = ""
        addTaskBean.remark = ""
        mBinding?.data = addTaskBean
//        mBinding?.executePendingBindings()
    }


}